package com.imdroid.carac.process;

import java.util.ArrayList;

import com.imdroid.carac.IMDroid;

public class MessageProcess {

	public static final int MAX_MESSAGE = 20;
	
	private static ArrayList<Message> messages = new ArrayList<Message>();
	
	/**
	 * 添加消息到列队
	 * @param msg
	 */
	public static void addMessage(Message msg){
			messages.add(msg);
			while(messages.size() > MAX_MESSAGE){
				messages.remove(messages.size() - 1);
			}
	}
	
	/**
	 * 删除指定ID的消息
	 * @param messageId
	 */
	public static void removeMessage(int messageId){
		Message toBeDel = null;
		for(Message msg : messages){
			if(msg.getMsgId() == messageId){
				toBeDel = msg;
				break;
			}
		}
		if(toBeDel != null)
			messages.remove(toBeDel);
	}
	
	/**
	 * 删除所有消息
	 */
	public void clearAllMessage(){
		messages.clear();
	}
	
	/**
	 * 获取所有消息
	 * @return
	 */
	public static ArrayList<Message> getAllMessages(){
		return messages;
	}
	
	/**
	 * 在消息列队里面显示的信息
	 */
	public static class Message {
		
		private int msgId;
		private long time;
		private String title;
		private MessageType type;
		
		public Message(long time, String title, MessageType type) {
			msgId = IMDroid.getNextMessageId();
			this.time = time;
			this.title = title;
			this.type = type;
		}

		public int getMsgId() {
			return msgId;
		}

		public long getTime() {
			return time;
		}

		public void setTime(long time) {
			this.time = time;
		}

		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		public MessageType getType() {
			return type;
		}

		public void setType(MessageType type) {
			this.type = type;
		}
		
	}
	
	public static enum MessageType {
		/**
		 * 安防信息
		 */
		SECURITY,
		/**
		 * 组队信息
		 */
		TEAM,
		/**
		 * 微博提醒
		 */
		WEIBO,
		/**
		 * ... 其他类型有待添加
		 */
	}
	
}
